import { z } from "zod";
export const userLoginSchema = z.object({
  account: z.string(),
  password: z.string(),
});
export type UserLoginType = z.infer<typeof userLoginSchema>;
export const userSignupSchema = z
  .object({
    account: z.string(),
    password: z.string(),
    passwordConfirm: z.string(),
  })
  // 自定义校验规则
  .refine((data) => data.password === data.passwordConfirm, {
    message: "两次密码输入不一致",
    path: ["passwordConfirm"],
  });
export type UserSignupType = z.infer<typeof userSignupSchema>;
export const userCreateSchema = z.object({
  _id: z.string().optional(),
  account: z.string(),
  password: z.string(),
  name: z.string().min(2, { message: "姓名至少为2个字符" }).optional(),
  age: z.number().int().min(0, { message: "年龄必须大于0" }).optional(),
  nickName: z.string().optional(),
  address: z.string().optional(),
  avatar: z.string().optional(),
  gender: z.string().optional(),
  phoneNumber: z
    .string()
    .refine((value) => /^1[3-9]\d{9}$/.test(value), "手机号码格式错误")
    .optional(),
  email: z.string().email().optional(),
  provider: z.enum(["gitee", "github"]).optional(),
  disabled: z.boolean().optional(),
  roles: z.array(z.string()).optional(),
  department: z.string().optional(),
  positions: z.array(z.string()).optional(),
});
export const userUpdateSchema = userCreateSchema.omit({ password: true });
export type UserCreateType = z.infer<typeof userCreateSchema>;
